package com.xiaoyao.login.listener;

import com.xiaoyao.login.pojo.DomainObject;
import org.springframework.core.Ordered;

/**
 * @Classname DomainObjectListener
 * @Description TODO
 * @Date 2022/4/20 17:07
 * @Created by Lenovo
 */
public interface DomainObjectListener<D extends DomainObject> extends Comparable, Ordered {
    int DEFAULT_ORDER = 1024;

    /**
     * execution order of current listener, and the lowest order value having the highest priority.
     * @return
     */
    default int getOrder() {
        return DEFAULT_ORDER;
    }

    default int compareTo(Object x) {
        return Integer.compare(getOrder(), ((DomainObjectListener) x).getOrder());
    }

    boolean supports(Object entity);

    //===============================================================================

    default void prePersist(D domainObject) {
    }

    default void postPersist(D domainObject) {
    }

    default void preUpdate(D domainObject) {
    }

    default void postUpdate(D domainObject) {
    }

    default void preRemove(D domainObject) {
    }

    default void postRemove(D domainObject) {
    }
}
